package king.dominic.jorc.core;

import android.graphics.Rect;

/**
 * Created by DominicKing on 2018/1/23.
 * 身份证区域
 */

public class Bounds {
    //性别
    public static Rect sex(Rect rect) {
        return cr(1.5f, 1.4f, 2.1f, 2f, rect);
    }
    //生日
    public static Rect birthday(Rect rect) {
        return cr(1.5f, 2f, 5.2f, 2.6f, rect);
    }

    //签证机关
    public static Rect visaOffice(Rect rect) {
        return cr(3.3f, 3.4f, 7.8f, 4.3f, rect);
    }

    //标题 背面：中华人民共和国
    public static Rect title(Rect rect) {
        return cr(2.6f, 0.2f, 8.2f, 1.3f, rect);
    }

    //日期
    public static Rect date(Rect rect) {
        return cr(3.4f, 4.2f, 7.8f, 4.9f, rect);
    }

    //国徽
    public static Rect nationalEmblem(Rect rect) {
        return cr(0.5f, 0.4f, 2.1f, 2.0f, rect);
    }

    //头像
    public static Rect avatar(Rect rect) {
        return cr(5.4f, 0.5f, 8.05f, 3.9f, rect);
    }

    //号码
    public static Rect number(Rect rect) {
        return cr(2.6f, 4.1f, 8.2f, 4.9f, rect);
    }

    //地址
    public static Rect address(Rect rect) {
        return cr(1.5f, 2.6f, 5.2f, 3.6f, rect);
    }

    //姓名
    public static Rect name(Rect rect) {
        return cr(1.5f, 0.5f, 5.2f, 1.2f, rect);
    }

    //创建区域
    private static Rect cr(float l, float t, float r, float b, Rect rect) {
        final int h = rect.height();
        final int w = rect.width();
        return new Rect(rect.left + h(w, l), rect.top + v(h, t), rect.left + h(w, r), rect.top + v(h, b));
    }

    //纵向
    private static int v(int height, float v) {
        return (int) (height * v / 5.3f);
    }

    //横向
    private static int h(int width, float h) {
        return (int) (width * h / 8.5f);
    }
}
